local powei = fk.CreateSkill{
  name = "lvshi__powei",
}

Fk:loadTranslationTable{
  ["lvshi__powei"] = "破围",
  [":lvshi__powei"] = "出牌阶段开始时，你可视为对任意名角色使用【杀】，若之仅对一名角色造成伤害，你于此阶段仅能对你或其使用牌，否则你<a href='chenzui_xushi'>蓄势此技能</a>。",

  ["#lvshi__powei"] = "破围：你可视为对任意名角色使用【杀】",
  ["@@powei_xushi"] = "破围 蓄势中",
  ["#lvshi__powei-refresh"] = "你可以弃置三张牌，重置破围",

  ["$lvshi__powei1"] = "敌聚如蝗，不可等闲视之。",
  ["$lvshi__powei2"] = "贼围甚密，唯乘夜伺隙。",
}

powei:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(powei.name) and target == player and player.phase == Player.Play
    and player:getMark("@@powei_xushi") == 0
  end,
  on_cost = function (self, event, target, player, data)
    local to = player.room:askToChoosePlayers(player, {
      targets = table.filter(player.room:getOtherPlayers(player), function (p)
        return player:canUseTo(Fk:cloneCard("slash"), p, {bypass_distances = true, bypass_times = true}) end),
      max_num = 99,
      min_num = 1,
      skill_name = powei.name,
      cancelable = true,
      prompt = "#lvshi__powei",
    })
    if #to > 0 then
      event:setCostData(self, to)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local tos = event:getCostData(self)
    local room = player.room
    local use = room:useVirtualCard("lvshi__slash", nil, player, tos, powei.name, true)
    if use.damageDealt then
      local players = table.filter(room:getAlivePlayers(), function (p) return use.damageDealt[p] and use.damageDealt[p] > 0 end)
      if #players == 1 then
        room:setPlayerMark(player, "lvshi__powei-phase", players[1].id)
      else
        room:addPlayerMark(player, "@@powei_xushi")
      end
    else
      room:addPlayerMark(player, "@@powei_xushi")
    end
  end
})

powei:addEffect("prohibit", {
  is_prohibited = function(self, from, to, card)
    if from:getMark("lvshi__powei-phase") ~= 0 then
      return from ~= to and from:getMark("lvshi__powei-phase") ~= to.id
    end
  end,
})

powei:addEffect(fk.AfterDrawPileShuffle, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(powei.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@powei_xushi", 0)
  end,
})

powei:addEffect("active", {
  prompt = "#lvshi__powei-refresh",
  anim_type = "special",
  card_num = 3,
  target_num = 0,
  can_use = function(self, player)
    return player:getMark("@@powei_xushi") > 0 and player:usedSkillTimes(powei.name, Player.HistoryRound) == 0
  end,
  card_filter = function (self, player, to_select, selected)
    if player:prohibitDiscard(to_select) then return false end
    return #selected < 3
  end,
  feasible = function (self, player, selected, selected_cards, card)
    return #selected_cards == 3
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:throwCard(effect.cards, powei.name, player, player)
    room:setPlayerMark(player, "@@powei_xushi", 0)
  end,
})

return powei